// pages/setSchedule/setSchedule.js
const app = getApp();
var dateTimePicker = require('../../../utils/dateTimePicker.js');
Page({

    /**
     * 页面的初始数据
     */
    data: {
      date: null,
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
      var time = require('../../../utils/util.js');
      var now = time.formatTime(new Date()).split(" ")[0];
      this.setData({
        date: now
      })
      console.log(this.data.date);
    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function () {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function () {

    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function () {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function () {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function () {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function () {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function () {

    },

    formSubmit: function(event){
      var time = require('../../../utils/util.js');
      var that = this;
      var start_time_ = new Date(this.data.date);
      console.log(start_time_);
      var capacity = event.detail.value.capacity;
      if(event.detail.value.time == 1)
        start_time_.setHours(9);
      else
        start_time_.setHours(15);
      start_time_.setMinutes(0);
      start_time_.setSeconds(0);
      var start_time = time.formatTime(start_time_);
      wx.request({
        url: app.globalData.base_request + '/doctor/setSchedule/' + app.globalData.userId + '/' + start_time + '/' + capacity,
        method: 'GET',
        success(res) {
          that.setData({
            message: res.data
          });
        },
        fail: function() {
          console.log("failure")  
        }
      });
      wx.navigateBack({
        delta: 0,
      })
    },

    changeDate(e){
      this.setData({ date:e.detail.value});
    }
})